package com.zhou.core.logana.handle.json.impl;

import com.alibaba.fastjson.JSON;
import com.zhou.core.os.v1.OSService;
import com.zhou.core.logana.LogRecord;
import com.zhou.core.logana.enums.RepositoryKeyEnum;
import com.zhou.core.logana.handle.json.AbstractJsonLogAnaHandler;
import com.zhou.util.TimeUtils;

/**
 * Created by zhouyongjun on 2020/6/12
 */
public class MemoryJsonLogAnaHandlerImpl extends AbstractJsonLogAnaHandler {
    @Override
    public String repositoryKey() {
        return RepositoryKeyEnum.MEMORY.name();
    }

    @Override
    public LogRecord handle(Object... params) {
        OSService.MemoryBean memoryBean = OSService.MemoryBean.obtainMemory();
        String key = TimeUtils.formatNoSpr(TimeUtils.now());
        jsonObject.put("value", JSON.toJSONString(memoryBean));
        jsonObject.put("datetime", key);
        LogRecord record = new LogRecord();
        record.setRepositoryKey(repositoryKey());
        record.setValue(jsonObject.toJSONString());
        record.setKey(key);
        return record;
    }


}
